package com.meilai.project.controller.web.system;

import com.meilai.project.dto.CommonResult;
import com.meilai.project.entity.system.Config;
import com.meilai.project.service.system.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author yxg
 * @Date 2020/8/14 15:31
 */
@Api(value = "Web端配置项控制器", description = "Web端配置项相关")
@RestController
@RequestMapping("api/web/dict")
public class WebConfigController {
    @Autowired
    private ConfigService service;

    @GetMapping("config_active_list")
    @ApiOperation(value = "启用中的配置项列表")
    public CommonResult configActionList() {
        return new CommonResult().success(service.configActionList());
    }

    @PostMapping("config_edit")
    @ApiOperation(value = "修改配置项")
    public CommonResult unitEdit(@RequestBody Config createParams) {
        int row = service.configEdit(createParams);
        if (row == 1) {
            return new CommonResult().success("修改成功");
        } else {
            return new CommonResult().failed("修改失败");
        }
    }

    @GetMapping("/getConfigByCode")
    @ApiOperation(value = "跟进code获取配置项")
    public CommonResult getConfigByCode(@RequestParam(value = "code") String code) {
        return new CommonResult().success(service.configDetail(code));
    }
}
